package com.example.framework2002;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.example.framework2002.storage.impl.MessageEvent;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class MainActivity2 extends AppCompatActivity {
    private static final String TAG = "SecondActivity.this";
    private TextView textView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        //需要接受数据的地方，注册EventBus
        EventBus.getDefault().register(this);
        textView = (TextView) findViewById(R.id.textView);
    }
    public void onClick(View view){
        startActivity(new Intent(this, MainActivity3.class));
    }
    //订阅方法，当接收到事件的时候，会调用该方法
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEvent(MessageEvent messageEvent){
        Log.d("123", "receive message222"+messageEvent.getMessage());
        textView.setText(messageEvent.getMessage());
        Toast.makeText(this, ""+messageEvent.getMessage(), Toast.LENGTH_SHORT).show();

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}